package com.example.streamsqlpark.entity;

import com.baomidou.mybatisplus.annotation.*;
import com.example.streamsqlpark.common.conf.K8sFlinkConfig;
import lombok.Data;

import java.util.Date;

/**
 * @author voloiono
 * @date 2024/4/19 16:09
 */
@Data
@TableName("t_flink_app")
public class FlinkApp {
    @TableId(type = IdType.AUTO)
    private Long id;

    private Long teamId;

    /** 1) custom code 2) flink SQL */
    private Integer jobType;

    private Long projectId;
    /** creator */
    private Long userId;

    /** The name of the frontend and program displayed in yarn */
    private String jobName;

    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String appId;

    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String jobId;

    /** The address of the jobmanager, that is, the direct access address of the Flink web UI */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String jobManagerUrl;

    /** flink version */
    private Long versionId;

    /** k8s cluster id */
    private String clusterId;

    /** flink docker base image */
    private String flinkImage;

    /** k8s namespace */
    private String k8sNamespace = K8sFlinkConfig.DEFAULT_KUBERNETES_NAMESPACE();

    private Integer state;
    /** task release status */
    @TableField("`release`")
    private Integer release;

    /** determine if a task needs to be built */
    private Boolean build;

    /** max restart retries after job failed */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Integer restartSize;

    /** has restart count */
    private Integer restartCount;

    private Integer optionState;

    /** alert id */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Integer alertId;

    private String args;
    /** application module */
    private String module;

    private String options;

    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String hotParams;

    private Integer resolveOrder;
    private Integer executionMode;
    private String dynamicProperties;
    private Integer appType;

    /** determine if tracking status */
    private Integer tracking;

    private String jar;

    /**
     * for upload type tasks, checkSum needs to be recorded whether it needs to be republished after
     * the update and modify.
     */
    private Long jarCheckSum;

    private String mainClass;

    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private String dependency;

    private Date startTime;

    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Date endTime;

    private Long duration;

    /** checkpoint max failure interval */
    private Integer cpMaxFailureInterval;

    /** checkpoint failure rate interval */
    private Integer cpFailureRateInterval;

    /** Actions triggered after X minutes failed Y times: 1: send alert 2: restart */
    private Integer cpFailureAction;

    /** overview */
    @TableField("TOTAL_TM")
    private Integer totalTM;

    private Integer totalSlot;
    private Integer availableSlot;
    private Integer jmMemory;
    private Integer tmMemory;
    private Integer totalTask;

    /** the cluster id bound to the task in remote mode */
    @TableField(updateStrategy = FieldStrategy.IGNORED)
    private Long flinkClusterId;

    private String description;

    private Date createTime;

    private Date optionTime;

    private Date modifyTime;

    /** The exposed type of the rest service of K8s(kubernetes.rest-service.exposed.type) */
    private Integer k8sRestExposedType;
    /** flink kubernetes pod template */
    private String k8sPodTemplate;

    private String k8sJmPodTemplate;
    private String k8sTmPodTemplate;

    private String ingressTemplate;
    private String defaultModeIngress;

    /** 1: cicd (build from csv) 2: upload (upload local jar job) */
    private Integer resourceFrom;

    /** flink-hadoop integration on flink-k8s mode */
    private Boolean k8sHadoopIntegration;

    private String tags;

    /** running job */
    private transient JobOverview.Task overview;

    private transient Long sqlId;
    private transient String flinkSql;

    private transient Integer[] stateArray;
    private transient Integer[] jobTypeArray;
    private transient Boolean backUp = false;
    private transient Boolean restart = false;
    private transient String userName;
    private transient String nickName;
    private transient String config;
    private transient Long configId;
    private transient String flinkVersion;
    private transient String confPath;
    private transient Integer format;
    private transient String savePoint;
    private transient Boolean savePointed = false;
    private transient Boolean drain = false;
    private transient Long savePointTimeout = 60L;
    private transient Boolean allowNonRestored = false;
    private transient String socketId;
    private transient String projectName;
    private transient String createTimeFrom;
    private transient String createTimeTo;
    private transient String backUpDescription;
    private transient String yarnQueue;

    /** Flink Web UI Url */
    private transient String flinkRestUrl;

    /** refer to {@link com.example.streamsqlpark.common.pipelin.BuildPipeline} */
    private transient Integer buildStatus;

    private transient AppControl appControl;
}
